package com.lkd.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lkd.dto.VmTypeDto;
import com.lkd.entity.VmType;
import com.lkd.mapper.VmTypeMapper;
import com.lkd.result.PageBean;
import com.lkd.service.VmTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VmTypeServiceImpl implements VmTypeService {

    @Autowired
    private VmTypeMapper vmTypeMapper;


    @Override
    public PageBean findByPage(VmTypeDto vmTypeDto) {
        //开启分页
        PageHelper.startPage(vmTypeDto.getPageIndex(), vmTypeDto.getPageSize());

        //执行查询
        List<VmType> list = vmTypeMapper.findList(vmTypeDto);
        Page<VmType> page = (Page<VmType>) list;

        //返回结果
        PageBean<VmType> pageBean = new PageBean<>();
        pageBean.setPageIndex(page.getPageNum());
        pageBean.setPageSize(page.getPageSize());
        pageBean.setTotalPage((long)page.getPages());
        pageBean.setTotalCount(page.getTotal());
        pageBean.setCurrentPageRecords(page.getResult());

        return pageBean;
    }

    @Override
    public Boolean save(VmType vmType) {
        return vmTypeMapper.save(vmType);
    }

    @Override
    public VmType findById(Integer typeId) {
        return vmTypeMapper.findByTypeId(typeId);
    }

    @Override
    public Boolean update(VmType vmType) {
        return vmTypeMapper.update(vmType);
    }

    @Override
    public Boolean deleteById(Integer typeId) {
        return vmTypeMapper.deleteById(typeId);
    }
}
